/* Author: CLR */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.IOException;

public class MemberList extends ObjectList {

    public MemberList() {
    }

    public Member loadObjectFromFile(String dataObject_String) throws FileNotFoundException {
        ArrayList<String> memberData = new ArrayList<String>();
        Scanner memberReader = new Scanner(dataObject_String);
        memberReader.useDelimiter(";");

        while (memberReader.hasNext()) {
            memberData.add(memberReader.next());
        }

        Member member = new Member(memberData.get(0), memberData.get(1), memberData.get(2),
                memberData.get(3), Boolean.parseBoolean(memberData.get(4)),
                memberData.get(5), memberData.get(6));

        if (member.getAgeGroup().equals("pensionist") && member.getMemberType().equals("Elite")) {
            member.setMemberType("Excercise");
        }
        
        return member;
    }

//Author BWH
//converterer et DataObjekt til Member Objekt
    public Member dataObjectToMember(DataObject obj) {
        String memb = obj.toString();
        ArrayList<String> memberData = new ArrayList<String>();
        Scanner memberReader = new Scanner(memb);
        memberReader.useDelimiter(";");

        while (memberReader.hasNext()) {
            memberData.add(memberReader.next());
        }

        Member member = new Member(memberData.get(0), memberData.get(1), memberData.get(2),
                memberData.get(3), Boolean.parseBoolean(memberData.get(4)),
                memberData.get(5), memberData.get(6));
        return member;
    }

    //Author BWH
    //overloader den anden hvis parametret er en arraylist
    public ArrayList<Member> dataObjectToMember(ArrayList<DataObject> temp) {
        ArrayList<Member> list = new ArrayList<Member>();
        for (int i = 0; i < temp.size(); i++) {
            list.add(dataObjectToMember(temp.get(i)));
        }
        return list;
    }
}